package com.yunxiao.cloud.mail.factory;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @description: MailSendFactory
 * @author: yunxiao
 * @date: 2020/3/6 11:14
 * @version: V1.0
 **/
public class MailSendFactory {

    private static JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();

    public static JavaMailSender getMailSender(String username, String password) {
        javaMailSender.setHost("smtp.exmail.qq.com");
        javaMailSender.setUsername(username);
        javaMailSender.setPassword(password);
        javaMailSender.setDefaultEncoding("UTF-8");
        Properties properties = new Properties();
        properties.setProperty("mail.smtp.host", "smtp.exmail.qq.com");
        properties.setProperty("mail.smtp.auth", "true");

        javaMailSender.setJavaMailProperties(properties);

        return javaMailSender;
    }
}
